home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / biglst / textview.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-05-07  |  5.0 KB  |  156 lines

  1. VERSION 2.00
  2. Begin Form TextView 
  3.    Caption         =   "Big Text File Viewer"
  4.    ClientHeight    =   4695
  5.    ClientLeft      =   1380
  6.    ClientTop       =   1605
  7.    ClientWidth     =   7500
  8.    FontBold        =   0   'False
  9.    FontItalic      =   0   'False
  10.    FontName        =   "MS Sans Serif"
  11.    FontSize        =   8.25
  12.    FontStrikethru  =   0   'False
  13.    FontUnderline   =   0   'False
  14.    Height          =   5100
  15.    Left            =   1320
  16.    LinkTopic       =   "Form1"
  17.    ScaleHeight     =   4695
  18.    ScaleWidth      =   7500
  19.    Top             =   1260
  20.    Width           =   7620
  21.    Begin CommandButton Command2 
  22.       Caption         =   "Quit"
  23.       Height          =   330
  24.       Left            =   1785
  25.       TabIndex        =   0
  26.       Top             =   210
  27.       Width           =   1065
  28.    End
  29.    Begin CommandButton Command1 
  30.       Caption         =   "Open File"
  31.       Height          =   330
  32.       Left            =   525
  33.       TabIndex        =   1
  34.       Top             =   210
  35.       Width           =   1065
  36.    End
  37.    Begin CommonDialog CMDialog1 
  38.       Left            =   6090
  39.       Top             =   1680
  40.    End
  41.    Begin PictureBox Picture2 
  42.       FontBold        =   0   'False
  43.       FontItalic      =   0   'False
  44.       FontName        =   "Fixedsys"
  45.       FontSize        =   9
  46.       FontStrikethru  =   0   'False
  47.       FontUnderline   =   0   'False
  48.       Height          =   1170
  49.       Left            =   6090
  50.       ScaleHeight     =   1140
  51.       ScaleWidth      =   405
  52.       TabIndex        =   4
  53.       Top             =   2415
  54.       Width           =   435
  55.    End
  56.    Begin PictureBox Picture1 
  57.       Height          =   2850
  58.       Left            =   210
  59.       ScaleHeight     =   2820
  60.       ScaleWidth      =   5655
  61.       TabIndex        =   3
  62.       Top             =   735
  63.       Width           =   5685
  64.    End
  65.    Begin VScrollBar VScroll1 
  66.       Height          =   750
  67.       LargeChange     =   10
  68.       Left            =   6195
  69.       TabIndex        =   2
  70.       Top             =   735
  71.       Width           =   225
  72.    End
  73.    Begin Label Label2 
  74.       Height          =   330
  75.       Left            =   5775
  76.       TabIndex        =   6
  77.       Top             =   270
  78.       Width           =   1695
  79.    End
  80.    Begin Label Label1 
  81.       Height          =   330
  82.       Left            =   3465
  83.       TabIndex        =   5
  84.       Top             =   270
  85.       Width           =   2115
  86.    End
  87. DefInt A-Z
  88. Dim FileArray(10000) As String * 80
  89. Dim LineCount, NLinesToShow
  90. Sub Command1_Click ()
  91.   On Error GoTo ErrHandler
  92.   CMDialog1.Filter = "All Files (*.*)|*.*"
  93.   CMDialog1.Action = 1            ' File Open Dialogue Box
  94.   file$ = CMDialog1.Filename      ' File Name
  95.   LineCount = 0
  96.   Open file$ For Input As #1
  97.     Filesize& = LOF(1)
  98.     Do Until EOF(1) Or LineCount = 10000
  99.       Line Input #1, lin$
  100.       FileArray(LineCount) = lin$
  101.       LineCount = LineCount + 1
  102.     Loop
  103.   Close
  104.   Label1.Caption = Str$(LineCount) + " lines available."
  105.   VScroll1.Max = LineCount - NLinesToShow   ' max value for scroll bar
  106.   VScroll1.Value = 0    ' reset for new file
  107.   PrintLines            ' print the lines Subroutine
  108. ErrHandler:
  109.   Exit Sub
  110. End Sub
  111. Sub Command2_Click ()
  112.   End
  113. End Sub
  114. Sub Form_Load ()
  115.   ' n lines to show in the "list box"
  116.   NLinesToShow = 15
  117.   TextView.Width = Screen.Width   ' form is maximum width
  118.   TextView.Left = 0               ' centre Picture1 on form
  119.   Picture1.Width = TextView.Width * .9
  120.   Picture1.Left = (TextView.Width - Picture1.Width - VScroll1.Width) \ 2
  121.   ScaleMode = 3    ' pixels
  122.   ' -1 to overlap the rt side of the picture box with the left side of the scroll
  123.   VScroll1.Left = Picture1.Left + Picture1.Width - 1
  124.   ScaleMode = 1    ' back to twips
  125.   ' determine the height of a line of text in Picture 2
  126.   ' make room for 15 lines of text + a bit of space at the bottom
  127.   Picture1.Height = (NLinesToShow + .2) * Picture2.TextHeight("A")
  128.   VScroll1.Height = Picture1.Height
  129.   VScroll1.Top = Picture1.Top
  130.   Picture2.AutoRedraw = True
  131.   Picture2.Left = -13000   ' move picture2 off the screen
  132.   Picture2.Height = Picture1.Height
  133.   Picture2.Width = Picture1.Width
  134.   VScroll1.LargeChange = NLinesToShow
  135. End Sub
  136. Sub PrintLines ()
  137.   FirstLine = VScroll1.Value
  138.   If FirstLine > LineCount - NLinesToShow Then
  139.     ' so we don't scroll past the end of the file
  140.     FirstLine = LineCount - NLinesToShow
  141.   End If
  142.   If FirstLine < 0 Then FirstLine = 0
  143.   ' if fewer lines in file than n lines height of list box
  144.   If NLinesToShow > LineCount Then NLinesToShow = LineCount - 1
  145.   Label2.Caption = "Top Line:" + Str$(FirstLine)
  146.   For I = FirstLine To FirstLine + NLinesToShow
  147.     Picture2.Print FileArray(I)  ' print lines to Picture2
  148.   Next I
  149.   ' copy lines in Picture2 over to Picture1
  150.   Picture1.Picture = Picture2.Image
  151.   Picture2.Cls    ' clear Picture2 for next lines
  152. End Sub
  153. Sub VScroll1_Change ()
  154.   PrintLines
  155. End Sub
  156.